<?php use_stylesheet('flexigrid_table') ?>
<?php use_javascript('/js/json_parse.js') ?>
<fieldset>
	<h1><?php echo $mainReportDef['title']?></h1>
	<h3><?php echo $mainReportDef['description']?></h3>
	<?php echo nl2br($mainReportDef['commentaire']) ?>

</fieldset>
<?php include_partial('formParameters', array('form' => $form,'dom'=>$dom)) ?>
<?php if(strtolower($mainReportDef['type'])=='grid'):?>
		<?php include_partial('reports/gridReport', array('reportdef' => $mainReportDef,'dom'=>$dom));?>
<?php elseif(($mainReportDef['type'])=='crossTable' or strtolower($mainReportDef['type'])=='table'):?>	
		<?php include_partial('reports/crosstableReport', array('reportdef' => $mainReportDef,'dom'=>$dom));?>
<?php elseif(strtolower($mainReportDef['type'])=='graph' or strtolower($mainReportDef['type'])=='chart'):?>	
		<?php include_partial('reports/graph', array('reportdef' => $mainReportDef,'dom'=>$dom));?>
<?php elseif(strtolower($mainReportDef['type'])=='jasperreport'):?>	
		<?php include_partial('reports/jasperReport', array('reportdef' => $mainReportDef,'dom'=>$dom));?>
<?php elseif(strtolower($mainReportDef['type'])=='download_xls'):?>	
		<?php include_partial('reports/downloadReport', array('reportdef' => $mainReportDef,'dom'=>$dom));?>
<?php elseif($mainReportDef['type']=='dashboard'):?>
	<fieldset id="reportcontent">
		<div id="sections" style="width: 100% ; float: left; display:none">
		<?php foreach($mainReportDef['sections'] as $xmlDef):?>
			<?php
				$code = $xmlDef->getAttribute('code');
				$width = $xmlDef->getAttribute('width');
				if(empty($width)) $width = '100%';
				$position = $xmlDef->getAttribute('position');
				if(empty($position)) $position = 'none';
				$style = $xmlDef->getAttribute('style');
				if(empty($style)) $style = '';
				$report = $boardReports[$code];
			?>
			<div class="section" style="width:<?php echo $width;?>;float:<?php echo $position;?>;<?php echo $style;?>">
				<h1><?php echo $report['title']?></h1>
				<h3><?php echo $report['description']?></h3>
				<?php echo nl2br($report['commentaire']) ?>
				<?php if(strtolower($report['type'])=='grid'):?>
						<?php include_partial('reports/gridReport', array('reportdef' => $report,'dom'=>$dom));?>
			  	<?php elseif(strtolower($report['type'])=='crosstable' or strtolower($report['type'])=='table'):?>
					  		<?php include_partial('reports/crosstableReport', array('reportdef' => $report,'dom'=>$dom));?>
			  	<?php elseif(strtolower($report['type'])=='chart' or strtolower($report['type'])=='graph'):?>
					  		<?php include_partial('reports/graph', array('reportdef' => $report,'dom'=>$dom));?>
			  	<?php elseif(strtolower($report['type'])=='template' or strtolower($report['type'])=='graph'):?>
					  		<?php include_partial('reports/templateReport', array('reportdef' => $report,'dom'=>$dom));?>
			  	<?php endif;?>
			</div>
		<?php endforeach;?>
		</div>
	</fieldset>
<?php endif;?>
<?php if($mainReportDef['type']=='chart' or $mainReportDef['type']=='graph'):?>
	<?php include_partial('reports/graph', array('reportdef' => $mainReportDef,'dom'=>$dom));?>
<?php endif;?>	


<script type="text/javascript">
<?php echo $reportDef['javascript'] ?>
</script>

<script type="text/javascript">
function refresh(){
<?php 
if(strtolower($mainReportDef['type'])=='dashboard'):
	foreach($boardReports as $report):
		if(strtolower($report['type'])=='graph' or strtolower($report['type'])=='chart'){
			echo  'refreshChart'. $report['id'] . '();' ;
		}else{
			echo  'refresh'. $report['id'] . '();' ;
		}
	endforeach;?>
		document.getElementById('sections').style.display='block';
<?php elseif(strtolower($mainReportDef['type'])=='graph' or strtolower($mainReportDef['type'])=='chart'):
	echo  'refreshChart'. $mainReportDef['id'] . '();' ;
else:
	echo  'refresh'. $mainReportDef['id'] . '();' ;
	if($mainReportDef['showDefaultChart']):
		echo  'refreshChart'. $mainReportDef['id'] . '();' ;
	endif;
endif;
?>
}
</script>